// MyChidFrameEdit.cpp : implementation file
//

#include "stdafx.h"
#include "waveeditor.h"
#include "MainFrm.h"
#include "MyChidFrameEdit.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// MyChidFrameEdit

IMPLEMENT_DYNCREATE(ChidEditScriptFrame, CMDIChildWnd)

ChidEditScriptFrame::ChidEditScriptFrame()
{
}

ChidEditScriptFrame::~ChidEditScriptFrame()
{
}


BEGIN_MESSAGE_MAP(ChidEditScriptFrame, CMDIChildWnd)
	//{{AFX_MSG_MAP(MyChidFrameEdit)
	ON_WM_CREATE()
	ON_COMMAND(ID_EDIT_CLOSE, OnEditClose)
	//}}AFX_MSG_MAP
	ON_WM_SIZING()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// MyChidFrameEdit message handlers

BOOL ChidEditScriptFrame::PreCreateWindow(CREATESTRUCT& cs) 
{
	// TODO: Add your specialized code here and/or call the base class
	CRect framerect;
	CRect srect;
	CRect trect;

	ParentMainFrame *pMainFrame = (ParentMainFrame *) AfxGetMainWnd();
	pMainFrame->GetClientRect(&framerect);
	pMainFrame->m_wndStatusBar	.GetWindowRect(&srect);
	pMainFrame->m_wndToolBar	.GetWindowRect(&trect);
	int	height	=	framerect.Height()-srect.Height()*2-trect.Height();
	cs.x		=	framerect.right/4;
	cs.y		=	framerect.top;
	cs.cx		=	framerect.right-cs.x;
	cs.cy		=	3*(height)/4;
	cs.style	&= ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX );//|WS_SYSMENU );
	
	return CMDIChildWnd::PreCreateWindow(cs);
}

int ChidEditScriptFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY )||//| CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.Load24BitToolBar( IDR_EDITSCRIPT, IDB_EDIT_SCRIPT_TOOLBAR_DISABLED ))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}


	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);
	
	return 0;
}


void ChidEditScriptFrame::OnEditClose() 
{
	// TODO: Add your command handler code here
	DestroyWindow();
}


void ChidEditScriptFrame::OnSizing(UINT fwSide, LPRECT pRect)
{
	CMDIChildWnd::OnSizing(fwSide, pRect);

	// TODO: Add your message handler code here
	CRect framerect;
	CRect srect;
	CRect trect;

	// TODO: Add your message handler code here
	ParentMainFrame *pMainFrame = (ParentMainFrame *) AfxGetMainWnd();
	pMainFrame->GetClientRect(&framerect);
	pMainFrame->m_wndStatusBar	.GetWindowRect(&srect);
	pMainFrame->m_wndToolBar	.GetWindowRect(&trect);
	int	height	=	framerect.Height()-srect.Height()*2-trect.Height();
	RECT	cs;
	cs.left		=	framerect.right/4;
	cs.top		=	framerect.top;
	cs.right	=	framerect.right;
	cs.bottom	=	framerect.top+3*(height)/4;
	MoveWindow(&cs);
}
